package com.woniu.controller;

import cn.dev33.satoken.util.SaResult;
import com.woniu.entity.dto.UserStatisticsDTO;
import com.woniu.entity.dto.scoreLevelDTO;
import com.woniu.service.UserStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("userStatistics")
public class UserStatisticsController {
    @Autowired
    private UserStatisticsService userStatisticsService;
    @GetMapping("/last7days")
    public Map<String, Object> getLast7DaysStatistics(){
        UserStatisticsDTO last7DaysStatistics = userStatisticsService.getLast7DaysStatistics();
        Map<String, Object> StatisticsMap = new HashMap<>();
        StatisticsMap.put("dates", last7DaysStatistics.getDates());
        StatisticsMap.put("newUserCounts", last7DaysStatistics.getNewUserCounts());
        StatisticsMap.put("activeUserCounts", last7DaysStatistics.getActiveUserCounts());
        return StatisticsMap;
    }
    //查询考试等级人数图标
    @GetMapping("/scoreLevel")
    public SaResult getScoreLevel(@RequestParam(required = false) String contestId){
        List<scoreLevelDTO> scoreLevel = new ArrayList<>();
        if(contestId==null || contestId.isEmpty()){
            scoreLevel = userStatisticsService.getScoreLevel(null);
        }else {
            scoreLevel = userStatisticsService.getScoreLevel(contestId);
        }
        return SaResult.ok().setData(scoreLevel);
    }
}
